<script setup lang='ts'>
import type { PlusColumn } from 'plus-pro-components'

import { SubmitBtn } from '@fl/components'

const id = defineModel<string>('id')
const visible = defineModel<boolean>('visible', { required: true })

const formRef = ref()

const formValues = ref({

    agreementName: '',
})

const columns: PlusColumn[] = [
    {
        label: '协议名称',
        prop: 'agreementName',
        width: 120,
    },

]

const dialog = computed(() => {
    return '编辑协议'
})
const rules = {
    agreementName: [
        {
            message: '请输入协议名称',
            required: true,
        },
    ],
}

async function confirm() {
    const valid = await formRef.value.formInstance.validate()
    if (valid) {
        console.log('提交')
    }
}

function cancel() {
    visible.value = false
}

function reset() {
    id.value = ''
    formRef.value.formInstance.resetFields()
}
</script>

<template>
    <PlusDialog v-model="visible"
                :title="dialog"
                width="800"
                close-on-press-escape
                @cancel="cancel"
                @closed="reset"
    >
        <!-- <ElSkeleton v-if="isLoading"
                    animated
        /> -->

        <PlusForm ref="formRef"
                  v-model="formValues"
                  :columns="columns"
                  :label-width="100"
                  :rules="rules"
                  :has-footer="false"
        />

        <template #footer>
            <div class="mx-auto">
                <el-button @click="cancel">
                    取消
                </el-button>

                <SubmitBtn type="primary"
                           @click="confirm"
                >
                    提交
                </SubmitBtn>
            </div>
        </template>
    </PlusDialog>
</template>
